<template>
  <div class="home-page">
    <div class="header-img">
      <img :src="homeImg"/>
    </div>
    <div class="content-block">
      <div class="info-list">
        <info-list-block :info-list="tztg" :banners="banners1" color="#409EFF"></info-list-block>
      </div>
      <div class="info-list" style="border-top: 1px dashed #E5E5EA">
        <info-list-block color="#67C23A" :info-list="jyky" :banners="banners2"></info-list-block>
      </div>
      <div class="news-info">
        <home-news-block></home-news-block>
      </div>
      <div class="trends-info">
        <home-trends-block></home-trends-block>
      </div>
      <div class="school-link">
        <home-map-link></home-map-link>
      </div>
    </div>

  </div>
</template>

<script>
import {getPage, getBanners} from "@/api/content";
//图片引入
import homeImg from '../../image/index/home.png'
//组件引入
import InfoListBlock from '../../components/home-info-list/home-info-list'
import HomeNewsBlock from '../../components/home-news-block/home-news-block'
import HomeTrendsBlock from '../../components/home-trends-block/home-trends-block'
import HomeMapLink from '../../components/home-map-link/home-map-link'
import {getLatestWztj} from "@/api/content";

export default {
  name: "home",
  created() {
    getPage({size:12},{or:[{subclassid_left_like: 'tztg'}], classid: 'tztg'}).then(res => {
      const that = this
      this.tztg = res.data.records
      this.tztg.forEach(item=>{
        const content = item.content
        if(item.titleimg){
          item.image = item.titleimg
          that.banners1.push(item)
        }else {
          const img = content.match(/<img[^>]+>/g);
          if (img) {
            if (img.length > 0) {
              console.log(img[0])
              img[0].replace(/<img [^>]*src=['"]([^'"]+)[^>]*>/gi, function (match, capture) {
                item.image = capture
                that.banners1.push(item)
              })
            }
          }
        }
      })
    })

    getPage({size:12},{or:[{subclassid_in: 'xkdt,zxxx,spxw_sshd'}], classid_left_like: 'dt'}).then(res => {
      this.jyky = res.data.records
            const that = this
      this.jyky.forEach(item=>{
        if(item.titleimg){
          item.image = item.titleimg
          that.banners1.push(item)
        }else {
          const content = item.content
          const img = content.match(/<img[^>]+>/g);
          if (img) {
            if (img.length > 0) {
              img[0].replace(/<img [^>]*src=['"]([^'"]+)[^>]*>/gi, function (match, capture) {
                item.image = capture
                that.banners2.push(item)
              })
            }
          }
        }
      })
    })

    getBanners().then(res => {
      this.banners = res.data
    })
  },
  components: {
    InfoListBlock,
    HomeNewsBlock,
    HomeTrendsBlock,
    HomeMapLink
  },
  data() {
    return {
      homeImg,
      tztg: [],
      jyky:[],
      banners1: [],
      banners2: [],
    }
  }
}
</script>

<style lang="scss" src="./index.scss" scoped>

</style>
